import Vue from "vue";
import ElementUI, {
    Message
} from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import qs from 'qs'
import App from "./App.vue";
import router from "./router";
import axios from 'axios'
import VueAxios from 'vue-axios'
import less from 'less'
import Cookie from "js-cookie";
Vue.prototype.Cookie = Cookie
Vue.use(less)
Vue.use(VueAxios, axios)
Vue.use(ElementUI);
Vue.config.productionTip = false;
Vue.prototype.qs = qs

router.beforeEach((to, from, next) => {
    //console.log(store.state.token)
    if (to.path === "/") return next();
    if (!Cookie.get("token")) return next("/");
    next();
});
// 弹框优化
const showMessage = Symbol('showMessage')
let messageInstance = null;
class DonMessage {
    success(options, single = true) {
        this[showMessage]('success', options, single)
    }
    warning(options, single = true) {
        this[showMessage]('warning', options, single)
    }
    info(options, single = true) {
        this[showMessage]('info', options, single)
    }
    error(options, single = true) {
            this[showMessage]('error', options, single)
        }
        [showMessage](type, options, single) {
            if (messageInstance && single) {
                messageInstance.close() //先把原来的关闭
            }
            messageInstance = Message[type](options) //再创建新的消息
        }
}
Vue.prototype.$message = new DonMessage()
new Vue({
    router,
    render: h => h(App)
}).$mount("#app");